package com.xwrite.toolkit;

import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * Supports creating and managing a {@link JPanel} for the Settings Dialog.
 */
public class AppSettingsComponent {

    private final JPanel mainPanel;
    private final JBTextField sdkPathText = new JBTextField();
    private final JBCheckBox deleteConflictingOutputs = new JBCheckBox("--delete-conflicting-outputs");

    public AppSettingsComponent() {
        mainPanel = FormBuilder.createFormBuilder()
                .addLabeledComponent(new JBLabel("Flutter SDK: "), sdkPathText, 1, false)
                .addComponent(deleteConflictingOutputs, 1)
                .addComponentFillVertically(new JPanel(), 0)
                .getPanel();
    }

    public JPanel getPanel() {
        return mainPanel;
    }

    public JComponent getPreferredFocusedComponent() {
        return sdkPathText;
    }

    @NotNull
    public String getSdkPathText() {
        return sdkPathText.getText().trim();
    }

    public void setSdkPathText(@NotNull String newText) {
        sdkPathText.setText(newText);
    }

    public boolean getDeleteConflictingOutputs() {
        return deleteConflictingOutputs.isSelected();
    }

    public void setDeleteConflictingOutputs(boolean newStatus) {
        deleteConflictingOutputs.setSelected(newStatus);
    }

}